package com.jsyh.maidu.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.jsyh.maidu.R;
import com.jsyh.maidu.adapter.home.CollectHotHolder;
import com.jsyh.maidu.adapter.home.GridHolder;
import com.jsyh.maidu.adapter.home.ImageHolder;
import com.jsyh.maidu.adapter.home.MyBaseViewHolder;
import com.jsyh.maidu.model.CollectionModel;

import java.util.List;

/**
 * Created by ZHY_9 on 2017/7/11.
 */

public class CollectionAdapter extends RecyclerView.Adapter {


    private List<Integer> viewType;
    Context context;
    CollectionModel model;

    public CollectionAdapter(List<Integer> viewType, Context context, CollectionModel model) {
        this.viewType = viewType;
        this.context = context;
        this.model = model;
    }

    @Override
    public int getItemViewType(int position) {
        return viewType.get(position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType){
            case 0:
                return new ImageHolder(context, LayoutInflater.from(context).inflate(R.layout.collect_img, parent, false), model.getAds());
            case 1:
                return new GridHolder(LayoutInflater.from(context).inflate(R.layout.collect_grid, parent, false), model.getAd(), model.getStores(), context);
            case 2:
                return new CollectHotHolder(LayoutInflater.from(context).inflate(R.layout.collect_hot, parent, false), context, model.getHot());

        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof MyBaseViewHolder){
            ((MyBaseViewHolder) holder).bindData();
        }
    }

    @Override
    public int getItemCount() {
        return viewType.size();
    }

}
